package com.javasm.crm.mapper.giftmapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasm.crm.domin.entity.gift.BindGiftList;
import com.javasm.crm.domin.entity.gift.GiftBind;
import com.javasm.crm.domin.entity.gift.GiftBindVo;
import com.javasm.crm.domin.entity.gift.GiftColor;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author whl
 * @since 2021-07-16
 */
@Mapper
@Repository
public interface GiftBindMapper extends BaseMapper<GiftBind> {

	@Select("select gb.bind_checkcomment bindCheckcomment,gb.bind_checktime bindChecktime,bind_goods.bind_id bindId,bind_goods.good_name goodname,gift_goods.gift_name giftname,gb.bind_checkid bindCheckid,gc.gift_checkid checkId,gc.gift_checkname checkName,gb.deleted from \n" +
			"(select bg.*,g.good_name from bind_goodlist bg, goods_info g\n" +
			"where bg.good_id = g.good_id)  bind_goods \n" +
			"left join \n" +
			"(select bgl.*,gi.gift_name from bind_giftlist bgl, gift_info gi \n" +
			"where bgl.gift_id=gi.gift_id) gift_goods\n" +
			"on bind_goods.bind_id = gift_goods.bind_id\n" +
			"LEFT JOIN\n" +
			"gift_bind gb on bind_goods.bind_id=gb.bind_id\n" +
			"LEFT JOIN\n" +
			"gift_check gc on gb.bind_checkid=gc.gift_checkId\n" +" ${ew.customSqlSegment}" +
			"group by gift_goods.bind_id")
	List<GiftBindVo> queryall(Page<GiftBindVo> pagination, @Param(Constants.WRAPPER) QueryWrapper<GiftBindVo> exampleQueryWrapper);

	@Select("SELECT gift.gift_id giftId,gift.gift_name giftName,gbind.bind_id bindId,bgiftl.giftlist_id giftListId\n" +
			"FROM gift_info gift\n" +
			"right JOIN bind_giftlist bgiftl ON bgiftl.gift_id=gift.gift_id \n" +
			"left  JOIN gift_bind gbind  ON bgiftl.bind_id=gbind.bind_id"+" ${ew.customSqlSegment}")
	List<GiftBindVo> queryGiftBindListById(@Param(Constants.WRAPPER) QueryWrapper<GiftBindVo> exampleQueryWrapper);

	@Select("SELECT good.good_id goodId,gbind.bind_id bindId,good.good_name goodName,bgoodl.goodlist_id goodListId\n" +
			"FROM gift_bind gbind\n" +
			"right  JOIN bind_goodlist bgoodl ON bgoodl.bind_id=gbind.bind_id\n" +
			"LEFT  JOIN goods_info good ON bgoodl.good_id=good.good_id"+" ${ew.customSqlSegment}")
	List<GiftBindVo> queryGoodBindListById(@Param(Constants.WRAPPER) QueryWrapper<GiftBindVo> exampleQueryWrapper);


}
